﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class Product_ChooseSupplier : Form
    {

        AddProduct addproduct;

        protected AddProduct AddProduct
        {
            get { return addproduct; }
        }
        
        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;

        public Product_ChooseSupplier(AddProduct addproduct)
        :this()
        {
            this.addproduct = addproduct;
        }
        
        public Product_ChooseSupplier()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();
        }

        protected void LoadData()
        {
            IQueryable<Supplier_Main> dataQuery = (from sm in diveDatabase.Supplier_Main
                                                  select sm);

            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;

            // Bind BindingSource to List
            SupplierList.DataSource = bindingSource;


            // Hide ID-Columns
            SupplierList.Columns["ID"].Visible = false;
            SupplierList.Columns["Firma"].Visible = true;
            SupplierList.Columns["KDNR_Lieferant"].Visible = false;

            // Set Column Headers
            SupplierList.Columns["Firma"].HeaderText = "Lieferant";


        }

        private void Product_ChooseSupplier_Load(object sender, EventArgs e)
        {
            LoadData();

            label1.Visible = true;
            label1.DataBindings.Add(new Binding("Text", bindingSource, "ID"));
            label1.Visible = false;
        }

        private void txChoose_Click(object sender, EventArgs e)
        {
            label1.Visible = true;
            AddProduct.Lieferant = label1.Text;
            DialogResult = DialogResult.OK;
            label1.Visible = false;
        }

        private void tbCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
